// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors, sized_box_for_whitespace, avoid_unnecessary_containers, avoid_print

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mybase/base/abstract/IFFR.dart';
import 'package:mybase/base/abstract/IFFRefresh.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/widget/layout/FFImageButton.dart';
import 'package:mybase/base/widget/layout/FFLineContainer.dart';
import 'package:mybase/base/widget/layout/FFNavi.dart';
import 'package:mybase/base/widget/layout/FFStackContainer.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFScaffold.dart';
import 'package:mybase/base/widgetTool/image/FFImageUtil.dart';

/**普通页面
 * 注意事项
 * 必须继承FFScaffold，FFScaffoldState，必须with MFFScaffold
 * 必须重写 iffScaffold，widget
 * 禁止重写initState,build,
 * 所有的父类属性，方法几乎是ff开头
 */
class WaterRipple extends FFScaffold {
  String? name;

  WaterRipple({Key? key, this.name}) : super(key: key);

  @override
  WaterRippleState createState() => WaterRippleState();
}

class WaterRippleState extends FFScaffoldState with MFFScaffold {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  WaterRipple get widget => super.widget as WaterRipple;

  /**固定写法end */
  /**刷新控件，不要刷新功能，则此值不传 */
  @override
  IFFRefresh? get iffRefresh => FFListPageStateRefresh();

  ///刷新控制

  bool boolValue = false;
  int index = 0;

  @override
  void ffInitState() {
    super.ffInitState();

    iffScaffold.ffStyle!.ffStatusBackgroundColor = Colors.white;
    // iffScaffold.ffStyle!.ffStatusTextColor = SystemUiOverlayStyle.dark;
    // iffScaffold.ffStyle!.ffBodyColor = Colors.white;
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNaviFast.navi(
      context,
      "普通页面",
      actionView: FFTextButton(
        text: "点我",
        alignment: Alignment.center,
        color: Colors.white,
        width: 60,
        heigth: FFNaviHeight,
        onClick: () {
          List list = [
            FFPageStatus.firstLoading,
            // WaterRippleStatus.noData,
            // WaterRippleStatus.netError,
            FFPageStatus.result
          ];
          index++;
          if (!(index < list.length)) {
            index = 0;
          }
          iffScaffold.ffPageStatus = list[index];
          setState(() {});
        },
      ),
    );
  }

  @override
  Widget? ffFirstLoadingWidget(BuildContext context) {
    return FFTextButton(
      color: Colors.yellow,
      text: "这是第一次菊花提示页",
    );
  }

  /**普通页面建议用CustomScrollView布局，可以配合默认刷新控件一起使用 */
  @override
  Widget? ffBody(BuildContext context) {
    List<Widget> slivers = [
      SliverToBoxAdapter(
        child: Container(
          color: Colors.black,
          child: FFLineContainer(
            children: [
              //1
              Material(
                child: InkWell(
                  onTap: () {},
                  child: Container(
                    height: 100,
                    width: 100,
                    child: Text("InkWell单击事件"),
                  ),
                ),
                color: Colors.yellow,
              ),
              //2
              Material(
                //INK可以实现装饰容器，实现矩形 设置背景色
                child: Ink(
                  color: Colors.purple,
                  child: InkWell(
                    onTap: () {},
                    child: Container(
                      width: 300.0,
                      height: 50.0,
                      decoration: BoxDecoration(
                        // color: Colors.purple,
                        borderRadius: BorderRadius.all(Radius.circular(30.0)),
                      ),
                      child: Text(
                        "登录",
                        style: TextStyle(color: Colors.white, fontSize: 16.0),
                      ),
                    ),
                  ),
                ),
              ),
              //3
              Material(
                child: Ink(
                  //设置背景
                  decoration: BoxDecoration(
                    color: Colors.purple,
                    borderRadius: BorderRadius.all(Radius.circular(30.0)),
                  ),
                  child: InkResponse(
                    borderRadius: BorderRadius.all(Radius.circular(30.0)),
                    //点击或者toch控件高亮时显示的控件在控件上层,水波纹下层
                    // highlightColor: Colors.purple[800],
                    //点击或者toch控件高亮的shape形状
                    highlightShape: BoxShape.rectangle,
                    //.InkResponse内部的radius这个需要注意的是，我们需要半径大于控件的宽，如果radius过小，显示的水波纹就是一个很小的圆，
                    //水波纹的半径
                    radius: 300.0,
                    //水波纹的颜色 设置了highlightColor属性后 splashColor将不起效果
                    splashColor: Color.fromRGBO(0, 0, 0, 0.01),
                    //true表示要剪裁水波纹响应的界面 false不剪裁 如果控件是圆角不剪裁的话水波纹是矩形
                    containedInkWell: true,
                    onTap: () {
                      print('click');
                    },
                    child: Container(
                      //不能在InkResponse的child容器内部设置装饰器颜色，否则会遮盖住水波纹颜色的，containedInkWell设置为false就能看到是否是遮盖了。
                      width: 300.0,
                      height: 50.0,
                      //设置child 居中
                      alignment: Alignment(0, 0),
                      child: Text(
                        "登录",
                        style: TextStyle(color: Colors.white, fontSize: 16.0),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    ];

    return CustomScrollView(slivers: slivers);
  }
}

class FFListPageStateRefresh with MFFRefresh {
  @override
  bool? ffCanRefreshFoot() {
    return false;
  }

  @override
  R ffRefresh(bool isHead) {
    print("调用接口...");
    Future.delayed(Duration(seconds: 2), () {
      ffRefreshCompleted();
    });
    return R();
  }
}
